require 'watir-webdriver'

module ZDDI

	module System_management
		class Server_management
			def open_sys_page
				ZDDI.browser.link(:href, "/system/services").click
				sleep 3
			end
			
			def init_server
				open_sys_page
				stb = ZDDI.browser.table(:index => 0)			
				if stb[2][1].html.include?"stoped" then
					stb[2][2].click
					puts "launch DHCP server"
				end
				if stb[3][1].html.include?"stoped" then
					stb[3][2].click
					puts "launch DNS server"
				end
			end
			
			
			def manage_server(server, state)
				open_sys_page
				stb = ZDDI.browser.table(:index => 0)
				if server.match("dhcp") then
					now_s = stb[2][1].html
					if now_s.match(state) then
						puts "#{server} state is #{state}"
					else
						stb[2][2].click
						puts "#{state} #{server}"
					end
				else
					now_s = stb[3][1].html
					if now_s.match(state) then
						puts "#{server} state is #{state}"
					else
						stb[3][2].click
						puts "#{state} #{server}"
					end
				end
			end						
		end
	end
	
end
